package com.snail.exception;


import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Monica
 * @description
 * @date 2025/7/10 15:18
 */
@Getter
public class BusinessException extends RuntimeException {

    /**
     * 错误码
     */
    private final int code;

    /**
     * 附加数据（可选）
     */
    private Map<String, Object> data = new HashMap<>();

    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
    }

    public BusinessException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
    }

    public BusinessException(ErrorCode errorCode, String message) {
        super(message);
        this.code = errorCode.getCode();
    }

    public BusinessException(ErrorCode errorCode, String message, Map<String, Object> data) {
        super(message);
        this.code = errorCode.getCode();
        this.data = data;
    }

}
